{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c70ca42d-01b7-4b9a-9bb4-8a17b494a6ac",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1. 显示信息\n",
      "2. 追加信息\n",
      "3. 删除信息\n",
      "4. 退出系统\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入数字1-4选择功能： 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1. 显示信息\n",
      "2. 追加信息\n",
      "3. 删除信息\n",
      "4. 退出系统\n"
     ]
    }
   ],
   "source": [
    "def display():\n",
    "   fi = open(\"address.csv\",'r')\n",
    "   for stuInfo in fi:\n",
    "       stuInfo=stuInfo.replace('\\n','')   \n",
    "       print(stuInfo)\n",
    "   fi.close()        \n",
    "def insertrec():\n",
    "   fo = open(\"address.csv\",'a')\n",
    "   rec = input(\"请输入要插入的信息，以逗号隔开（示例：103,cc,34567,tianjin）：\")\n",
    "   fo.write(rec)\n",
    "   fo.write('\\n')   \n",
    "   fo.close()\n",
    "def deleterec():\n",
    "   fi = open(\"address.csv\",'r')\n",
    "   reInfo=[]\n",
    "   for stuInfo in fi:\n",
    "       reInfo.append(stuInfo.replace('\\n',''))\n",
    "   fi.close()\n",
    "   fo = open(\"address.csv\",'w')\n",
    "   sid = input(\"请输入要删除的信息（示例：103）：\")\n",
    "   for stuInfo in reInfo:\n",
    "       if not stuInfo.startswith(sid) :\n",
    "           fo.write(stuInfo) \n",
    "           fo.write('\\n')   \n",
    "   fo.close()\n",
    "menu=[\"1. 显示信息\",\"2. 追加信息\",\"3. 删除信息\",\"4. 退出系统\"]\n",
    "flag = 1\n",
    "while flag:\n",
    "    for m in menu:\n",
    "       print(m)\n",
    "    try:\n",
    "       ch = int(input(\"请输入数字1-4选择功能：\") )\n",
    "       flag =1\n",
    "    except:\n",
    "       flag = 0\n",
    "    if ch <1 or ch > 4:\n",
    "       flag = 1 \n",
    "    elif ch ==1:\n",
    "       display()\n",
    "    elif ch==2:\n",
    "       insertrec()\n",
    "    elif ch ==3:\n",
    "       deleterec()\n",
    "    elif ch ==4:\n",
    "       break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5314b0b-a6cc-4e6e-a473-12ef66e268e0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
